﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ObviousCode.Stately
{
    public class Transition<T> where T : struct, IConvertible
    {
        public Transition(T from, T to)
        {
            From = from;
            To = to;
        }

        public T From { get; private set; }
        public T To { get; private set; }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            Transition<T> compare = obj as Transition<T>;

            if (compare == null) return false;

            return compare.From.Equals(From) &&
                     compare.To.Equals(To);
        }

        public override int GetHashCode()
        {
            return From.GetHashCode() ^ To.GetHashCode();
        }

        public static bool operator ==(Transition<T> lhs, Transition<T> rhs)
        {
            if (System.Object.ReferenceEquals(lhs, rhs))
            {
                return true;
            }

            // If one is null, but not both, return false.
            if (((object)lhs == null) || ((object)rhs == null))
            {
                return false;
            }

            return lhs.To.Equals(rhs.To) &&
                     lhs.From.Equals(rhs.From);
        }

        public static bool operator !=(Transition<T> lhs, Transition<T> rhs)
        {
            return !(lhs == rhs);
        }

        public override string ToString()
        {
            return "{0} -> {1}".F(From, To);
        }
    }
}
